#pragma once

#define mfree(p) if(p) {delete p;p=0;}
#define mfrees(p) if(p) {delete []p;p=0;}
//#define BeginMemberDeclare() private: byte MemberFlag1;
//#define EndMemberDeclare() private: byte MemberFlag2;
//#define ZeroMember() ZeroMemory(&MemberFlag1,(char*)&MemberFlag2+sizeof(MemberFlag2)-(char*)&MemberFlag1)
#define ZeroClass(dst) ZeroMemory(&(dst),sizeof((dst)))
#define ZeroMemberR(elm) ZeroMemory(&elm,(char*)this+sizeof(*this)-(char*)&elm)
#define ZeroInit(cls) (cls)(){ZeroMemory(this,sizeof(*this));}
#define ZeroInitR(cls,elm) (cls)(){ZeroMemory(&elm,(char*)this+sizeof(*this)-(char*)&elm);}
//#define foreach(max) for(int i=0;i<(max);i++)
#define foreach(var,min,max) for(int (var)=(min);(var)<(max);(var)++)
#define strcmpA(src,dst) (strcmp((src).c_str(),(dst))==0)
#define strcmpW(src,dst) (wcscmp((wchar_t*)(src).c_str(),(dst))==0)



//free Resource
namespace CusFun
{
	void InitRes();
	void FreeRes();
}


//STL
#define foreach_stl(it,storage) for((it)=(storage).begin();(it)!=(storage).end();(it)++)
#define foreach_stlI(it,storage) int stoIndex=0;for((it)=(storage).begin();(it)!=(storage).end();(it)++,stoIndex++)
#define foreach_stlR(it,storage,min,max) for((it)=(storage).begin()+(min);(it)!=((storage).begin()+(max));(it)++)
#define foreach_stlRI(it,storage,min,max) int stoIndex=0;for((it)=(storage).begin()+(min);(it)!=((storage).begin()+(max));(it)++,stoIndex++)
#define free_stlvct(it,storage) for((it)=(storage).begin();(it)!=(storage).end();(it)++){delete *(it);*(it)=0;}
#define free_stlmap(it,storage) for((it)=(storage).begin();(it)!=(storage).end();(it)++){delete (it)->second;(it)->second=0;}

namespace StlFun
{
	template<class T> T Pop(vector<T>& sto)
	{
		T elm;
		elm=*sto.begin();
		sto.erase(sto.begin());
		return elm;
	}
};

//String Function
#define StringArray vector<string>
#define StringProp map<string,StringArray>
namespace StrFun
{
	StringArray SplitStr(const char* Str,char* SpChar,char* Prefix=0);
	void ParseStream(StringArray& Str,const char* Stream);
	void MakeStream(string& Stream,StringArray& Str);
};

//Environment
namespace EnvFun
{
	string GetAppPath();

	/*DynID*/
	int GetDynID(int Type);
	void ReleaseDynID(int ID);
	static vector<int> DynIDs[3];
};

//GDI
class MDC;
namespace GdiFun
{
	void InitRes();
	void FreeRes();
	CFont* GetSimSunFont(int FontSize);
	CBrush* GetBrush(int Color);
	MDC* CreateMemoryDC(CWnd* Wnd);
	void TransparentBkg(CWnd* Window,COLORREF Color);
	static ULONG_PTR hGdiplus;
	static map<int,CFont*> Fonts;
	static map<int,CBrush*> Brush;
};

//Math
namespace MathFun
{
	int GetRnd(int Mod,int Spec=0);
}

//define
#define WM_SELECT_CHANGE 13000
#define WM_FIND_CHILDWINDOW 13001
//#define NOTIFY_SELECT_CHANGE 14000